import java.util.Iterator;


public class CoverageCorner {
	
	public static void main (String[] args) {
		
		League myLeague = new League();
		myLeague.SetLeagueName("Coverage Corner League");
		AddTeams(myLeague);
		MatchUp[] matchups = CreateMatchups(myLeague);
		RecentScore[] scores = CreateRecentScores();
		MainScreen ms = new MainScreen();
		ms.runMainScreen(myLeague, matchups, scores);
		
	}
	
	private static void AddTeams(League league) {
		for(int i = 1; i <= 11; i++) {
			Team team = new Team();
			team.SetOwnerName("Owner " + i);
			team.SetTeamName("Team " + i);
			PopulateTeam(team, i);
			int losses = i - 1;
			int wins = 10 - losses;
			boolean winStreak = (Math.random() * wins) > (Math.random() * losses);
			if(winStreak) {
				team.SetStreak("W" + (int)Math.ceil((Math.random() * wins)));
			} else {
				team.SetStreak("L" + (int)Math.ceil((Math.random() * losses)));
			}
			if(i == 1)
				team.SetStreak("W10");
			if(i == 11)
				team.SetStreak("L10");
			team.SetRecord(wins + "-" + losses);
			league.AddMember(i, team);
		}
		
		
	}

	private static void PopulateTeam(Team team, int i) {
		//Add Quarterback
		TeamMem player = new TeamMem(team.GetTeamName(), "Quarterback", team.GetTeamName(), "QB");
		player.InputPoints((int) (Math.random() * 20 * (15-i)));
		player.InputMoves((int) (Math.random() * 3));
		SetPoints(player, i, 20);
		player.setPassTDs((int) (Math.random() * ((15-i) / 2)));
		player.setTotalPassTDs((int) (Math.random() * ((15-i) / 3) * 10));
		player.setPassYards((int)(Math.random() * ((15 - i) / 3) * 30));
		player.setTotalPassYards((int)(Math.random() * ((15 - i) / 3) * 30 * 10));
		player.setRushYards((int)(Math.random() *((15-i)/3) * 5));
		player.setRushYards((int)(Math.random() *((15-i)/3) * 5 * 10));
		team.AddTeam(player);
		
		//Add Runningbacks
		player = new TeamMem(team.GetTeamName(), "Runningback 1", team.GetTeamName(), "RB");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 2));
		SetPoints(player, i, 15);
		player.setRushYards((int)(Math.random() * (15-i)/3 * 35));
		player.setTotalRushYards((int)(Math.random() * (15-i)/3 * 35 * 10));
		player.setRushTDs((int)(Math.random() * (15-i)/3));
		player.setTotalRushTDs((int)(Math.random() * (15-i)/3 * 10));
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 3));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 3) * 10);
		team.AddTeam(player);
		player = new TeamMem(team.GetTeamName(), "Runningback 2", team.GetTeamName(), "RB");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 2));
		SetPoints(player, i, 15);
		player.setRushYards((int)(Math.random() * (15-i)/3 * 35));
		player.setTotalRushYards((int)(Math.random() * (15-i)/3 * 35 * 10));
		player.setRushTDs((int)(Math.random() * (15-i)/3));
		player.setTotalRushTDs((int)(Math.random() * (15-i)/3 * 10));
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 3));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 3) * 10);
		team.AddTeam(player);
		
		//Add Wide Receivers
		player = new TeamMem(team.GetTeamName(), "Wide Receiver 1", team.GetTeamName(), "WR");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 2));
		SetPoints(player, i, 12);
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 30));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 30) * 10);
		player.setTotalReturnTDs((int)(Math.random() * .65));
		player.setReceivingTDs((int)(Math.random() * (15-i)/5));
		player.setTotalReceivingTDs((int)(Math.random() * (15-i)/5 * 10));
		team.AddTeam(player);
		player = new TeamMem(team.GetTeamName(), "Wide Receiver 2", team.GetTeamName(), "WR");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 1));
		SetPoints(player, i, 12);
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 30));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 30) * 10);
		player.setTotalReturnTDs((int)(Math.random() * .65));
		player.setReceivingTDs((int)(Math.random() * (15-i)/5));
		player.setTotalReceivingTDs((int)(Math.random() * (15-i)/5 * 10));
		team.AddTeam(player);
		player = new TeamMem(team.GetTeamName(), "Wide Receiver 3", team.GetTeamName(), "WR");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 1));
		SetPoints(player, i, 12);
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 30));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 30) * 10);
		player.setTotalReturnTDs((int)(Math.random() * .65));
		player.setReceivingTDs((int)(Math.random() * (15-i)/5));
		player.setTotalReceivingTDs((int)(Math.random() * (15-i)/5 * 10));
		team.AddTeam(player);
		
		//Add Tight End
		player = new TeamMem(team.GetTeamName(), "Tight End", team.GetTeamName(), "TE");
		player.InputPoints((int) (Math.random() * 10 * (15-i)));
		player.InputMoves((int) (Math.random() * 3));
		SetPoints(player, i, 5);
		player.setRushYards((int)(Math.random() * (15-i)/3 * 35));
		player.setReceivingYards((int)(Math.random() * (15-i)/3 * 10));
		player.setTotalReceivingYards((int)(Math.random() * (15-i)/3 * 10) * 10);
		player.setReceivingTDs((int)(Math.random() * (15-i)/3 * Math.random() / 3));
		player.setTotalReceivingTDs((int)(Math.random() * (15-i)/3 * Math.random() / 3 * 10));
		team.AddTeam(player);
		
		//Add Kicker
		player = new TeamMem(team.GetTeamName(), "Kicker", team.GetTeamName(), "K");
		player.InputPoints((int) (Math.random() * 15 * (15-i)));
		player.InputMoves((int) (Math.random() * 2));
		SetPoints(player, i, 15);
		team.AddTeam(player);
		
		//Add Defense
		player = new TeamMem(team.GetTeamName(), "Defense", team.GetTeamName(), "DEF");
		player.InputPoints((int) (Math.random() * 25 * (15-i)));
		player.InputMoves((int) (Math.random() * 1));
		SetPoints(player, i, 25);
		player.setTotalFumbleTDs((int)(Math.random() * (15 - i) / 5));
		player.setWeekInts((int)(Math.random() * (15 - i) / 5));
		player.setSeasonInts((int)(Math.random() * (15 - i) / 5) * 10);
		team.AddTeam(player);
		
		
	}
	
	private static void SetPoints (TeamMem player, int teamRank, int multiplier) {
		player.setProjectedPoints(multiplier - (int)(Math.random() * (teamRank) * (multiplier/10))+ (int)(Math.random() * (15 - teamRank) * (multiplier/10))/2);
	}
	
	private static MatchUp[] CreateMatchups(League league) {
		MatchUp[] matchups = new MatchUp[5];
		for(int i = 1; i <= 5; i++) {
			Team teamA = league.GetMember(i);
			Team teamB = league.GetMember(11-i);
			int PointsA = 0;
			Iterator<TeamMem> team = teamA.GetTeam();
			while(team.hasNext()) {
				TeamMem player = team.next();
				PointsA += (int)player.getProjectedPoints();
			}
			int PointsB = 0;
			team = teamB.GetTeam();
			while(team.hasNext()) {
				TeamMem player = team.next();
				PointsB += (int) player.getProjectedPoints();
			}
						
			matchups[i-1] = new MatchUp(teamA,PointsA,teamB,PointsB);
		}
		return matchups;

	}
	
	private static RecentScore[] CreateRecentScores() {
		RecentScore[] recentScores = new RecentScore[15];
		recentScores[0] = new RecentScore("3","Team1", "Kicker  makes 15 Yard FG");
		recentScores[1] = new RecentScore("9","Team3", "Receiver 1 scores 35 Yard TD");
		recentScores[2] = new RecentScore("6","Team2", "Runningback 2 scores 3 Yard TD");
		recentScores[3] = new RecentScore("7","Team5", "Receiver 2 scores 18 Yard TD");
		recentScores[4] = new RecentScore("3","Team6", "Kicker  makes 25 Yard FG");
		recentScores[5] = new RecentScore("7","Team10", "Runningback 2 scores 11 Yard TD");
		recentScores[6] = new RecentScore("9","Team1", "Receiver 2 scores 39 Yard TD");
		recentScores[7] = new RecentScore("3","Team3", "Kicker  makes 22 Yard FG");
		recentScores[8] = new RecentScore("6","Team8", "Runningback 1 scores 2 Yard TD");
		recentScores[9] = new RecentScore("7","Team2", "Receiver 3 scores 15 Yard TD");
		recentScores[10] = new RecentScore("8","Team1", "Runningback 1 scores 23 Yard TD");
		recentScores[11] = new RecentScore("3","Team9", "Kicker  makes 33 Yard FG");
		recentScores[12] = new RecentScore("3","Team7", "Kicker  makes 28 Yard FG");
		recentScores[13] = new RecentScore("7","Team3", "Receiver 1 scores 18 Yard TD");
		recentScores[14] = new RecentScore("7","Team1", "Receiver 2 scores 15 Yard TD");
		return recentScores;
	}
	

}
